﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Imaginecup.observer
{
    //단순히 연결시켜주는 역활
    public class CommunicationMan
    {
        private List<IObserver> m_Observer = new List<IObserver>();
        private List<ISubject> m_Subject = new List<ISubject>();


        public void AddObserver(IObserver observer)
        {
            m_Observer.Add(observer);
        }

        public void AddSubject(ISubject subject)
        {
            m_Subject.Add(subject);
        }


        //등록하자마자 해제
        public void RegisterCommunicationWithRelease()
        {
            foreach( ISubject subject in m_Subject )
            {
                foreach( IObserver observer in m_Observer )
                {
                    //같은 값은 등록시키지 않는다.
                    if (observer.Equals(subject))
                        continue;

                    subject.AddObserver(observer);
                }
            }

            m_Observer.Clear();
            m_Subject.Clear();

            m_Observer = null;
            m_Subject = null;
        }
     
    }
}
